<html><head><title>EntityAnimation2.pb</title></head>
<body bgcolor="#FFFFDF" link="#009999" vlink="#006666" alink="#006666">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#006666">;
</font><font color="#006666">; ------------------------------------------------------------
</font><font color="#006666">;
</font><font color="#006666">;   PureBasic - EntityAnimation
</font><font color="#006666">;
</font><font color="#006666">;    (c) Fantaisie Software
</font><font color="#006666">;
</font><font color="#006666">; ------------------------------------------------------------
</font><font color="#006666">;
</font><font color="#006666">;Cursor = Move Robot
</font><font color="#006666">;Speed animation = PageUp and PageDown 
</font>

<b><font color="#006666">IncludeFile</font></b> <font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Screen3DRequester.pb"

<b><font color="#006666">Define</font></b>.f KeyX, KeyY, MouseX, MouseY, Speed = 1.0
<b><font color="#006666">Define</font></b>.i RobotMove


<b><font color="#006666">If</font></b> <font color="#006666">InitEngine3D</font>()
  
  
<font color="#006666">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Data/Textures", <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#006666">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Data/Models", <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#006666">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Data/Scripts", <font color="#924B72">#PB_3DArchive_FileSystem</font>)
<font color="#006666">  Add3DArchive</font>(<font color="#924B72">#PB_Compiler_Home</font> + "examples/3d/Data/Packs/Desert.zip", <font color="#924B72">#PB_3DArchive_Zip</font>)
<font color="#006666">  Parse3DScripts</font>()
  
<font color="#006666">  InitSprite</font>()
<font color="#006666">  InitKeyboard</font>()
<font color="#006666">  InitMouse</font>()
  
  <b><font color="#006666">If</font></b> <font color="#006666">Screen3DRequester</font>()
    
<font color="#006666">    WorldShadows</font>(<font color="#924B72">#PB_Shadow_Modulative</font>, -1,<font color="#006666"> RGB</font>(75, 75, 75))
    
    <font color="#006666">;Ground
</font>    <font color="#006666">;
</font><font color="#006666">    CreateMaterial</font>(0,<font color="#006666"> LoadTexture</font>(0, "Dirt.jpg"))
<font color="#006666">    CreatePlane</font>(0, 1500, 1500, 40, 40, 15, 15)
<font color="#006666">    CreateEntity</font>(0,<font color="#006666">MeshID</font>(0),<font color="#006666">MaterialID</font>(0))
<font color="#006666">    EntityRenderMode</font>(0, 0)
    
    <font color="#006666">;Mesh
</font>    <font color="#006666">;
</font><font color="#006666">    LoadMesh</font>(1, "robot.mesh")
    
    <font color="#006666">; Entity
</font>    <font color="#006666">;
</font><font color="#006666">    CreateEntity</font>(1,<font color="#006666"> MeshID</font>(1), <font color="#924B72">#PB_Material_None</font>)
    
    <font color="#006666">; SkyBox
</font>    <font color="#006666">;
</font><font color="#006666">    SkyBox</font>("Desert07.jpg")
    
    <font color="#006666">; Camera
</font>    <font color="#006666">;
</font><font color="#006666">    CreateCamera</font>(0, 0, 0, 100, 100)
<font color="#006666">    MoveCamera</font>(0, 50, 100, 180,<font color="#924B72">#PB_Absolute</font>)
<font color="#006666">    CameraLookAt</font>(0,<font color="#006666"> EntityX</font>(1),<font color="#006666"> EntityY</font>(1) + 40,<font color="#006666"> EntityZ</font>(1))
    
    
<font color="#006666">    CreateLight</font>(0,<font color="#006666"> RGB</font>(255, 255, 255), -40, 100, 80)
<font color="#006666">    AmbientColor</font>(<font color="#006666">RGB</font>(80, 80, 80))
    
    <b><font color="#006666">Repeat</font></b>
<font color="#006666">      Screen3DEvents</font>()
      
      <b><font color="#006666">If</font></b> <font color="#006666">ExamineMouse</font>()
        MouseX = -<font color="#006666">MouseDeltaX</font>()/10 
        MouseY = -<font color="#006666">MouseDeltaY</font>()/10
      <b><font color="#006666">EndIf</font></b>
      
      RobotMove = <font color="#924B72">#False</font>    
      <b><font color="#006666">If</font></b> <font color="#006666">ExamineKeyboard</font>()
        
        <b><font color="#006666">If</font></b> <font color="#006666">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Left</font>)
<font color="#006666">          MoveEntity</font>(1, -1 * Speed, 0, 0)
<font color="#006666">          RotateEntity</font>(1, 0, 180, 0)
          RobotMove = <font color="#924B72">#True</font>
        <b><font color="#006666">ElseIf</font></b> <font color="#006666">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Right</font>)
<font color="#006666">          MoveEntity</font>(1, 1 * Speed, 0, 0)
<font color="#006666">          RotateEntity</font>(1, 0, 0, 0)
          RobotMove = <font color="#924B72">#True</font>
        <b><font color="#006666">ElseIf</font></b> <font color="#006666">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Up</font>)
<font color="#006666">          MoveEntity</font>(1, 0, 0, -1 * Speed)
<font color="#006666">          RotateEntity</font>(1, 0, 90, 0)
          RobotMove = <font color="#924B72">#True</font>
        <b><font color="#006666">ElseIf</font></b> <font color="#006666">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Down</font>)
<font color="#006666">          MoveEntity</font>(1, 0, 0, 1 * Speed)
<font color="#006666">          RotateEntity</font>(1, 0, -90, 0)
          RobotMove = <font color="#924B72">#True</font>
        <b><font color="#006666">EndIf</font></b>
        
        <b><font color="#006666">If</font></b> <font color="#006666">KeyboardPushed</font>(<font color="#924B72">#PB_Key_PageUp</font>) <b><font color="#006666">And</font></b> Speed &#060; 1.0
          Speed + 0.05
        <b><font color="#006666">ElseIf</font></b> <font color="#006666">KeyboardPushed</font>(<font color="#924B72">#PB_Key_PageDown</font>) <b><font color="#006666">And</font></b> Speed &#062; 0.1 
          Speed - 0.05
        <b><font color="#006666">EndIf</font></b>
        
      <b><font color="#006666">EndIf</font></b>
      
      <b><font color="#006666">If</font></b> RobotMove
        <b><font color="#006666">If</font></b> <font color="#006666">EntityAnimationStatus</font>(1, "Walk") = <font color="#924B72">#PB_EntityAnimation_Stopped</font> <font color="#006666">; Loop
</font><font color="#006666">          StartEntityAnimation</font>(1, "Walk", <font color="#924B72">#PB_EntityAnimation_Manual</font>) <font color="#006666">; Start the animation from the beginning
</font>        <b><font color="#006666">EndIf</font></b>
      <b><font color="#006666">Else</font></b>
<font color="#006666">        StopEntityAnimation</font>(1, "Walk")
      <b><font color="#006666">EndIf</font></b>
      
<font color="#006666">      AddEntityAnimationTime</font>(1, "Walk", TimeSinceLastFrame)
      
<font color="#006666">      RotateCamera</font>(0, MouseY, MouseX, RollZ, <font color="#924B72">#PB_Relative</font>)
<font color="#006666">      MoveCamera  </font>(0, KeyX, 0, KeyY)
      
      TimeSinceLastFrame =<font color="#006666"> RenderWorld</font>() * Speed
      
<font color="#006666">      FlipBuffers</font>()
    <b><font color="#006666">Until</font></b> <font color="#006666">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Escape</font>) <b><font color="#006666">Or</font></b> Quit = 1
  <b><font color="#006666">EndIf</font></b>
  
<b><font color="#006666">Else</font></b>
<font color="#006666">  MessageRequester</font>("Error", "The 3D Engine can't be initialized",0)
<b><font color="#006666">EndIf</font></b>

<b><font color="#006666">End</font></b>
</font></pre>
</body></html>
